package com.jy.wms.service;

import com.github.pagehelper.PageHelper;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.dao.StatisticsOfDistributionOfProvincesMapper;
import com.jy.wms.pojo.WmsOrderDistribution;
import com.jy.wms.pojo.WmsOrderDistributionStatistics;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class StatisticsOfDistributionOfProvincesService extends BaseService<StatisticsOfDistributionOfProvincesMapper,WmsOrderDistribution> {


    /**
     * 各省订单分布统计（根据时间查询）
     *
     * @param
     * @return list
     */
    public JSONObject orderdistributionstatistics(WmsOrderDistribution WmsOrderDistribution, String hzid, String ckid) throws IOException {
        //将数据添加到map集合中
        JSONObject allJson = new JSONObject();
        JSONArray array=new JSONArray();
        List<WmsOrderDistributionStatistics> order=new ArrayList<>();
        //时间
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(WmsOrderDistribution.getFpsj_start()!=null && !"".equals(WmsOrderDistribution.getFpsj_start())){
            java.sql.Date date =new java.sql.Date(new Long(WmsOrderDistribution.getFpsj_start()));
            WmsOrderDistribution.setFpsj_start(sdf.format(date));
        }
        if(WmsOrderDistribution.getFpsj_end()!=null && !"".equals(WmsOrderDistribution.getFpsj_end())){
            java.sql.Date date=new Date(new Long(WmsOrderDistribution.getFpsj_end()));
            WmsOrderDistribution.setFpsj_end(sdf.format(date));
        }

        if(WmsOrderDistribution.getFpsj_start()!=null && WmsOrderDistribution.getFpsj_end()!=null){
            String start_time = WmsOrderDistribution.getFpsj_start();
            String End_time=WmsOrderDistribution.getFpsj_end();

            PageHelper.startPage(WmsOrderDistribution.getPage(), WmsOrderDistribution.getRows());
            order = dao.orderdistributionstatistics(start_time,End_time, hzid, ckid);
        }
        array = JSONArray.fromObject(order);
        allJson = SetStatus.setSearchType(array.toString(), order.size());
        //allJson.put("contentList", order);
        return allJson;
    }


    /**
     * 各省订单分布统计报表导出（根据时间查询）
     *
     * @param
     * @return list
     */

    public List<WmsOrderDistributionStatistics> baseSelectBathPrimaryKeys(WmsOrderDistributionStatistics WmsOrderDistributionStatistics, String hzid, String ckid) {
        //时间
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(WmsOrderDistributionStatistics.getFpsj_start()!=null && !"".equals(WmsOrderDistributionStatistics.getFpsj_start())){
            java.sql.Date date =new java.sql.Date(new Long(WmsOrderDistributionStatistics.getFpsj_start()));
            WmsOrderDistributionStatistics.setFpsj_start(sdf.format(date));
        }
        if(WmsOrderDistributionStatistics.getFpsj_end()!=null && !"".equals(WmsOrderDistributionStatistics.getFpsj_end())){
            java.sql.Date date=new Date(new Long(WmsOrderDistributionStatistics.getFpsj_end()));
            WmsOrderDistributionStatistics.setFpsj_end(sdf.format(date));
        }
        List<com.jy.wms.pojo.WmsOrderDistributionStatistics> order = dao.orderdistributionstatisticsExport(WmsOrderDistributionStatistics);

        return order;
    }
}
